#delimit;
u $data\allsample, clear;
keep if sample==1;

local eteachercont cbyerace1 cbyerace2 cbyerace3 cbyerace4 cbyerace5 egend byte26c byte26c_sq
      emajor cbytehdeg cbyte29 i.byte01 i.byte03;
local mteachercont cbymrace1 cbymrace2 cbymrace3 cbymrace4 cbymrace5 mgend bytm26c bytm26c_sq
	  mmajor cbytmhdeg cbytm29 i.bytm01 i.bytm03;
local teacherchar `eteachercont' `mteachercont';
local studentchar cbyrace1-cbyrace5 gend noneng cbyplang 
	  byfathed2-byfathed4 bymothed2-bymothed4 cbyfcomp inc2 inc3 inc4 highincome
	  cbyp38;


by tidmth, sort: gen Nm = _N;
by tideng, sort: gen Ne = _N;


label var T1 "Expect College (ELA)";
label var T2 "Expect College (Math)";


gen Yyear = 10 if f3attainment==1;
replace Yyear = 12 if f3attainment==2;
replace Yyear = 13 if f3attainment==3;
replace Yyear = 14 if f3attainment>=4 & f3attainment<=5;
replace Yyear = 16 if f3attainment==6;
replace Yyear = 17 if f3attainment==7;
replace Yyear = 18 if f3attainment==8;
replace Yyear = 19 if f3attainment==9;
replace Yyear = 21 if f3attainment==10;

gen T1year = 10 if byte20==1;
replace T1year=12 if byte20==2;
replace T1year=14 if byte20==3;
replace T1year=15 if byte20==4;
replace T1year=16 if byte20==5;
replace T1year=18 if byte20==6;
replace T1year=21 if byte20==7;

gen T2year = 10 if bytm20==1;
replace T2year=12 if bytm20==2;
replace T2year=14 if bytm20==3;
replace T2year=15 if bytm20==4;
replace T2year=16 if bytm20==5;
replace T2year=18 if bytm20==6;
replace T2year=21 if bytm20==7;



gen lesshs = f3attainment==1;
gen t1lesshs = byte20==1;
gen t2lesshs = bytm20==1;

gen t1neqt2 = T1~=T2;
gen t2gt1 = T2>T1;

gen mhs = bymothed1+bymothed2;
gen t1white = 1-cbyerace6;
gen t2white = 1-cbymrace6;
gen mcol = bymothed>=6;

/* this creates Table 1: Analytic Sample Means - Students */;


label var Y "Completed College or more";
label var lesshs "Completed $<$ HS Diploma";
label var Yyear "Education Completed, Years";
label var T1 "College or More, ELA";
label var t1lesshs "Expect $<$ HS, ELA";
label var T1year "ELA Teacher Expected Years";
label var T2 "College or More, Math";
label var t2lesshs "Expect $<$ HS, Math";
label var T2year "Math Teacher Expected Years";
label var t1neqt2 "Teacher Expectations Disagree";
label var t2gt1 "Math Teacher has Higher Expectations";
label var bytxrstd "Reading Assessment";
label var bytxmstd "Math Assessment";
label var lowincome "Household Income $<$ 20K";
label var highincome "Household Income $>$ 100K";
label var mhs "Mother has $\leq$ HS Diploma";
label var mcol "Mother has a Bachelor's or More";
label var t1white "ELA Teacher Non-White";
label var t2white "Math Teacher Non-White";
label var cbyerace3 "ELA Teacher Black";
label var cbymrace3 "Math Teacher Black";


eststo clear;
qui eststo: estpost sum Y lesshs Yyear  T1 t1lesshs T1year T2 t2lesshs T2year t1neqt2 t2gt1
 bytxrstd bytxmstd f1rgp9 lowincome highincome mhs mcol t1white t2white cbyerace3 cbymrace3;
 estadd scalar nst = round(e(N),10);

qui eststo: estpost sum Y lesshs Yyear T1 t1lesshs T1year T2 t2lesshs T2year t1neqt2 t2gt1
 bytxrstd bytxmstd f1rgp9 lowincome highincome mhs mcol t1white t2white cbyerace3 cbymrace3 if cbyrace6;
 estadd scalar nst = round(e(N),10);

 qui eststo: estpost sum Y lesshs Yyear T1 t1lesshs T1year T2 t2lesshs T2year t1neqt2 t2gt1
 bytxrstd bytxmstd f1rgp9 lowincome highincome mhs mcol t1white t2white cbyerace3 cbymrace3 if cbyrace3;
 estadd scalar nst = round(e(N),10);

 qui eststo: estpost sum Y lesshs Yyear T1 t1lesshs T1year T2 t2lesshs T2year t1neqt2 t2gt1
 bytxrstd bytxmstd f1rgp9 lowincome highincome mhs mcol t1white t2white cbyerace3 cbymrace3 if gend;
 estadd scalar nst = round(e(N),10);

 qui eststo: estpost sum Y lesshs Yyear T1 t1lesshs T1year T2 t2lesshs T2year t1neqt2 t2gt1
 bytxrstd bytxmstd f1rgp9 lowincome highincome mhs mcol t1white t2white cbyerace3 cbymrace3 if gend==0;
 estadd scalar nst = round(e(N),10);

esttab using $table\table1.tex, replace label cells(mean(fmt(2)) sd(fmt(2) par))
noobs stats(nst, fmt(0) labels("Observations"))
refcat(Y "\hspace{-0.5em}\textbf{Educational Attainment}" T1 "\hspace{-0.5em}\textbf{Teacher Expectations}"
bytxrstd "\hspace{-0.5em}\textbf{Academic Backbround}" lowincome "\hspace{-0.5em}\textbf{Demographics and Socioeconomic Status}"
t1white "\hspace{-0.5em}\textbf{Teacher Demographics}"
, nolabel) title("Analytic Sample Means - Students")
collabels(none);




/* Table: Analytic Sample Means - Students, Teacher Expectations Coincide  */
preserve;
keep if T1==T2;
eststo clear;
qui eststo: estpost sum Y lesshs Yyear  T1 t1lesshs T1year T2 t2lesshs T2year t1neqt2 t2gt1
 bytxrstd bytxmstd f1rgp9 lowincome highincome mhs mcol t1white t2white cbyerace3 cbymrace3;
 estadd scalar nst = round(e(N),10);

qui eststo: estpost sum Y lesshs Yyear T1 t1lesshs T1year T2 t2lesshs T2year t1neqt2 t2gt1
 bytxrstd bytxmstd f1rgp9 lowincome highincome mhs mcol t1white t2white cbyerace3 cbymrace3 if cbyrace6;
 estadd scalar nst = round(e(N),10);

 qui eststo: estpost sum Y lesshs Yyear T1 t1lesshs T1year T2 t2lesshs T2year t1neqt2 t2gt1
 bytxrstd bytxmstd f1rgp9 lowincome highincome mhs mcol t1white t2white cbyerace3 cbymrace3 if cbyrace3;
 estadd scalar nst = round(e(N),10);

 qui eststo: estpost sum Y lesshs Yyear T1 t1lesshs T1year T2 t2lesshs T2year t1neqt2 t2gt1
 bytxrstd bytxmstd f1rgp9 lowincome highincome mhs mcol t1white t2white cbyerace3 cbymrace3 if gend;
 estadd scalar nst = round(e(N),10);

 qui eststo: estpost sum Y lesshs Yyear T1 t1lesshs T1year T2 t2lesshs T2year t1neqt2 t2gt1
 bytxrstd bytxmstd f1rgp9 lowincome highincome mhs mcol t1white t2white cbyerace3 cbymrace3 if gend==0;
 estadd scalar nst = round(e(N),10);

esttab using $table\table_s7.tex, append label cells(mean(fmt(2)) sd(fmt(2) par))
noobs stats(nst, fmt(0) labels("Observations"))
refcat(Y "\hspace{-1em}\textbf{Educational Attainment}" T1 "\hspace{-1em}\textbf{Teacher Expectations}"
bytxrstd "\hspace{-1em}\textbf{Academic Backbround}" lowincome "\hspace{-1em}\textbf{Demographics and Socioeconomic Status}"
t1white "\hspace{-1em}\textbf{Teacher Demographics}"
, nolabel) title("Analytic Sample Means - Students, Teacher Expectations Coincide \label{tab:sumsame}")
collabels(none)
;
restore;
preserve;
keep if T1~=T2;


/* Table: Analytic Sample Means - Students, Teacher Expectations Disagree  */
eststo clear;
qui eststo: estpost sum Y lesshs Yyear  T1 t1lesshs T1year T2 t2lesshs T2year t1neqt2 t2gt1
 bytxrstd bytxmstd f1rgp9 lowincome highincome mhs mcol t1white t2white cbyerace3 cbymrace3;
 estadd scalar nst = round(e(N),10);

qui eststo: estpost sum Y lesshs Yyear T1 t1lesshs T1year T2 t2lesshs T2year t1neqt2 t2gt1
 bytxrstd bytxmstd f1rgp9 lowincome highincome mhs mcol t1white t2white cbyerace3 cbymrace3 if cbyrace6;
 estadd scalar nst = round(e(N),10);

 qui eststo: estpost sum Y lesshs Yyear T1 t1lesshs T1year T2 t2lesshs T2year t1neqt2 t2gt1
 bytxrstd bytxmstd f1rgp9 lowincome highincome mhs mcol t1white t2white cbyerace3 cbymrace3 if cbyrace3;
 estadd scalar nst = round(e(N),10);

 qui eststo: estpost sum Y lesshs Yyear T1 t1lesshs T1year T2 t2lesshs T2year t1neqt2 t2gt1
 bytxrstd bytxmstd f1rgp9 lowincome highincome mhs mcol t1white t2white cbyerace3 cbymrace3 if gend;
 estadd scalar nst = round(e(N),10);

 qui eststo: estpost sum Y lesshs Yyear T1 t1lesshs T1year T2 t2lesshs T2year t1neqt2 t2gt1
 bytxrstd bytxmstd f1rgp9 lowincome highincome mhs mcol t1white t2white cbyerace3 cbymrace3 if gend==0;
 estadd scalar nst = round(e(N),10);

esttab using $table\table_s8.tex, append label cells(mean(fmt(2)) sd(fmt(2) par))
noobs stats(nst, fmt(0) labels("Observations"))
refcat(Y "\hspace{-1em}\textbf{Educational Attainment}" T1 "\hspace{-1em}\textbf{Teacher Expectations}"
bytxrstd "\hspace{-1em}\textbf{Academic Backbround}" lowincome "\hspace{-1em}\textbf{Demographics and Socioeconomic Status}"
t1white "\hspace{-1em}\textbf{Teacher Demographics}"
, nolabel) title("Analytic Sample Means - Students, Teacher Expectations Differ \label{tab:sumdiff}")
collabels(none)
;
restore;
